package com.google.gwt.demo.client;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.HasText;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.event.dom.client.ChangeEvent;

public class TestWidget extends AbstractComposite<TestWidget.Presenter> implements HasText, HasClickHandlers{

	private static TestWidgetUiBinder uiBinder = GWT
		.create(TestWidgetUiBinder.class);

	interface TestWidgetUiBinder extends UiBinder<Widget, TestWidget> {
	}

	public interface Presenter extends AbstractComposite.Presenter{
		
	}
	
	@Override
	protected void initWidget() {
		initWidget(uiBinder.createAndBindUi(this));
	}

	@UiField
	Button button;
	@UiField TextBox textBox;

	private String prop1;

	public enum EnumTest{Choix1, Choix2};
	
	private EnumTest prop2;

	public void setText(String text) {
		button.setText(text);
	}

	public String getText() {
		return button.getText();
	}

	public void setProp1(String prop1) {
		this.prop1 = prop1;
		autoUpdate();
	}
	
	public String getProp1(){
		return prop1;
	}

	public void setProp2(EnumTest prop2){
		this.prop2 = prop2;
		autoUpdate();
	}

	public EnumTest getProp2(){
		return this.prop2;
	}
	
	public TestWidget(){
		super();
	}

	public TestWidget(Presenter presenter){
		super(presenter);
	}

	@Override
	protected Presenter getDefaultPresenter(){
		return new DefaultPresenter(this);
	}

	@Override
	public HandlerRegistration addClickHandler(ClickHandler handler) {
		return addHandler(handler, ClickEvent.getType());
	}
	@UiHandler("textBox")
	void onTextBoxChange(ChangeEvent event) {
		Window.alert("changement");
	}
} 